package com.example.book_manager_project.Controller;
import com.example.book_manager_project.mapper.BookMapper;
import com.example.book_manager_project.model.BookManager;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Type;

@RestController
@RequestMapping("/book")
public class BookController {
   @Resource
   private BookMapper bookMapper;
    @PostMapping("/addBook")
    public String addBook(@RequestBody BookManager bookManager){
        int insert =  bookMapper.insert(bookManager);
        return String.valueOf(insert);
    }
    @PutMapping("/updateBook")
    public String updateBook(@RequestBody BookManager bookManager){
        if (null==bookManager.getId()){
            return "id is not null";
        }
        int update =  bookMapper.updateById(bookManager);
        return String.valueOf(update);
    }
    @DeleteMapping("/detectBook")
    public String deleteBook(@RequestParam Integer id){
        int insert =  bookMapper.deleteById(id);
        return String.valueOf(insert);
    }
    @GetMapping("/getBook")
    public BookManager selectBook(@RequestParam Integer id){
        return bookMapper.selectById(id);
    }
}